package com.caishi.lkx.user.login;

import cn.hutool.core.util.StrUtil;
import com.caishi.lkx.user.dto.LoginDto;
import com.caishi.lkx.user.ienum.type.UserAccountType;
import com.caishi.lkx.user.model.IUserModel;
import com.caishi.lkx.user.model.LoginInfoModel;
import com.caishi.lkx.user.service.ILoginInfoService;
import com.zzw.common.exception.BizException;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author by keray
 * date:2019/8/9 22:04
 */
@Service(value = "groupLoginService")
class GroupLoginServiceImpl extends UsernameLoginServiceImpl {
    @Resource
    private ILoginInfoService userLoginService;


    @Override
    public LoginInfoModel loginBase(LoginDto loginDto, HttpServletRequest request, HttpServletResponse response) throws BizException {
        return super.loginBase(loginDto, request, response);
    }

    @Override
    public IUserModel register(LoginInfoModel loginInfoModel, IUserModel userModel) throws BizException {
        IUserModel registerModel = super.register(loginInfoModel, userModel);
        // 存在手机号新增手机号 密码登录
        if (StrUtil.isNotBlank(userModel.getMobile())) {
            userLoginService.userAddNewLogin(userModel.getMobile(),
                    LoginService.passwordEncryption(loginInfoModel.getCertificate()),
                    UserAccountType.username,
                    registerModel.getId()
            );
        }
        return registerModel;
    }
}
